#include <iostream>
#include <string>
using namespace std;

int main() {
    cout << "Введите скобочную последовательность: ";
    string s;
    getline(cin, s);
    string s1 = "";
    bool f = false;
    for (char& c : s) {
        cout << s1 << endl;
        if (c == '(' || c == '[' || c == '<' || c == '{') {
            s1 += c;
        }
        else if (c != ' ') {
            if (s1.length() > 0) {
                if ((s1[s1.length() - 1] == '(' && c == ')') ||
                    (s1[s1.length() - 1] == '{' && c == '}') ||
                    (s1[s1.length() - 1] == '[' && c == ']') ||
                    (s1[s1.length() - 1] == '<' && c == '>')) {
                    s1 = s1.substr(0, s1.length() - 1);
                }
                else {
                    f = true;
                }
            }
            else {
                f = true;
            }
        }
        if (f) {
            break;
        }
    }
    cout << s1 << endl;
    if (!f) {
        cout << "Верная" << endl;
    }
    else {
        cout << "Неверная" << endl;
    }
    return 0;
}
